home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Sources / RectShp.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  6.7 KB  |  268 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                RectShp.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef RECTSHP_H
  23. #include "RectShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. // ----- Foundation Includes -----
  107.  
  108. #ifndef FWSTREAM_H
  109. #include "FWStream.h"
  110. #endif
  111.  
  112. // ----- OpenDoc Includes -----
  113.  
  114. #ifndef SOM_ODTransform_xh
  115. #include <Trnsform.xh>
  116. #endif
  117.  
  118. //========================================================================================
  119. // Runtime Information
  120. //========================================================================================
  121.  
  122. #ifdef FW_BUILD_MAC
  123. #pragma segment odfdrawshapes
  124. #endif
  125.  
  126. //========================================================================================
  127. // RunTime Info
  128. //========================================================================================
  129.  
  130. FW_DEFINE_CLASS_M1(CRectShape, CBoundedShape)
  131.  
  132. FW_REGISTER_ARCHIVABLE_CLASS(LRectShape, CRectShape, CRectShape::Read, CBaseShape::Write)
  133.  
  134. //========================================================================================
  135. // class CRectShape
  136. //========================================================================================
  137.  
  138. //----------------------------------------------------------------------------------------
  139. // CRectShape::CRectShape
  140. //----------------------------------------------------------------------------------------
  141.  
  142. CRectShape::CRectShape() :
  143.     CBoundedShape(kRectShape, kFrameOnly)
  144. {
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. // CRectShape::CRectShape
  149. //----------------------------------------------------------------------------------------
  150.  
  151. CRectShape::CRectShape(unsigned short shapeType, unsigned short renderVerb) :
  152.     CBoundedShape(shapeType, renderVerb)
  153. {
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // CRectShape::CRectShape
  158. //----------------------------------------------------------------------------------------
  159.  
  160. CRectShape::CRectShape(FW_CReadableStream& archive) :
  161.     CBoundedShape(archive)
  162. {    
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. // CRectShape::~CRectShape
  167. //----------------------------------------------------------------------------------------
  168.  
  169. CRectShape::~CRectShape()
  170. {
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. // CRectShape::RenderShape
  175. //----------------------------------------------------------------------------------------
  176.  
  177. void CRectShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  178. {
  179.     FW_CRect rect(fRect);
  180.     AdjustRectForPenSize(rect, GetPenSize());
  181.  
  182.     if (HasFillStyle())
  183.         FW_CRectShape::RenderRect(gc, rect, FW_kFill, fFillInk, fFillStyle);
  184.     
  185.     if (HasFrameStyle())
  186.         FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // CRectShape::HitTest
  191. //----------------------------------------------------------------------------------------
  192.  
  193. FW_Boolean CRectShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  194. {
  195.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  196.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  197.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  198.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  199.     
  200.     FW_CRect bounds(fRect);
  201.     AdjustRectForPenSize(bounds, GetPenSize());
  202.  
  203.     FW_CRectShape rectShape(bounds, HasFillStyle() ? FW_kFill : FW_kFrame);
  204.     return rectShape.HitTest(gc, mouse, FW_IntToFixed(2));
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. // CRectShape::OutlineShape
  209. //----------------------------------------------------------------------------------------
  210.  
  211. void CRectShape::OutlineShape(FW_CGraphicContext& gc, const FW_PInk& ink, const FW_PStyle& style, const FW_CRect& rect)
  212. {
  213.     FW_CRect bounds(rect);
  214.     AdjustRectForPenSize(bounds, style->GetPenSize());
  215.     FW_CRectShape::RenderRect(gc,
  216.                               bounds,
  217.                               FW_kFrame,
  218.                               ink, style);
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. // CRectShape::GetClipRegion
  223. //----------------------------------------------------------------------------------------
  224.  
  225. void CRectShape::GetClipRegion(Environment *ev, ODShape* clipRegion)
  226. {
  227.     FW_CRect bounds(fRect);
  228.     AdjustRectForPenSize(bounds, GetPenSize());
  229.     
  230.     ODRect odBounds = bounds;
  231.     clipRegion->SetRectangle(ev, &odBounds);
  232.     
  233.     if (FrameOnly())
  234.     {
  235.         bounds.Inset(GetPenSize(), GetPenSize());
  236.         
  237.         FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev, bounds);
  238.         clipRegion->Subtract(ev, aqTempShape);
  239.     }
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. // CRectShape::CreateShapeOutline
  244. //----------------------------------------------------------------------------------------
  245.  
  246. ODShape* CRectShape::CreateShapeOutline(Environment *ev)
  247. {
  248.     FW_CRect bounds(fRect);
  249.     AdjustRectForPenSize(bounds, GetPenSize());
  250.  
  251.         // We don't acquire it because we return it
  252.     ODShape* dragRgn = ::FW_NewODShape(ev, bounds);
  253.  
  254.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  255.  
  256.     return dragRgn;
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. // CRectShape::Read
  261. //----------------------------------------------------------------------------------------
  262.  
  263. void* CRectShape::Read(FW_CReadableStream& archive)
  264. {
  265.     return new CRectShape(archive);
  266. }
  267.  
  268.